package com.platform;

import cn.hutool.log.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * SpringBoot方式启动类
 */
@SpringBootApplication
public class PlatformApplication implements CommandLineRunner {

    private static final Log log = Log.get();

    @Autowired
    private DataSource dataSource;

    public static void main(String[] args) {
        SpringApplication.run(PlatformApplication.class, args);
        log.info("^_^ >>> " + PlatformApplication.class.getSimpleName() + " is success!");
    }

    @Override
    public void run(String... args) throws Exception {
        try (Connection conn = dataSource.getConnection()) {
            // 这里，可以做点什么
            log.info("[run][获得连接：{}]", conn);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
